﻿using System;
using System.Windows.Forms;
using System.Drawing.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;

namespace SedionFormDesigner.CusControls.TypeEditor
{
    class ImageEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;
            if (context != null && context.Instance != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null)
                {
                    OpenFileDialog openFile = new OpenFileDialog();
                    openFile.RestoreDirectory = false;
                    openFile.Filter = "JPGE|*.jpg|BMP|*.bmp|所有文件|*.*";
                    if (openFile.ShowDialog() == DialogResult.OK)
                    {
                        value = openFile.FileName;
                    }
                    return value;
                }
            }
            return base.EditValue(context, provider, value);
        }
    }
}
